﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using School.Controls;

namespace School.WebPages
{
    public partial class Search : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string type = Request.QueryString["type"];
            string keyWord = Request.QueryString["key"];

            string proName = string.Empty;
            switch (type)
            {
                case "0":
                    proName = "FindArticleByKey";
                    break;
                case "1":
                    proName = "FindDownloadByKey";
                    break;
                case "2":
                    proName = "FindTeacherByKey";
                    break;
                default:
                    break;
            }

            SqlDataReader sdr = DAL.SearchHelper.FindInfos(proName, keyWord);

            if (type == "0")
            {
                ArticleList articles = (ArticleList)Page.LoadControl("~/Controls/ArticleList.ascx");
                articles.DataSource = sdr;
                this.PlaceHolder1.Controls.Add(articles);
            }
            else if (type == "1")
            {
                DownloadFileList files = (DownloadFileList)Page.LoadControl("~/Controls/DownloadFileList.ascx");
                files.DataSource = sdr;
                PlaceHolder1.Controls.Add(files);
            }
            else
            {
                TeacherList teachers = (TeacherList)Page.LoadControl("~/Controls/TeacherList.ascx");
                teachers.DataSource = sdr;
                PlaceHolder1.Controls.Add(teachers);
            }
        }
    }
}
